package com.sqnu.util;

import com.sqnu.javabean.User;
import mapper.UserMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.List;

public class UserTest {
    SqlSession session;
    UserMapper mapper;
    @Before
    public void before(){
        SqlSessionFactory factory = MyBatisUtil.getSqlSessionFactory();
        session = factory.openSession(true);
        mapper = session.getMapper(UserMapper.class);
    }
    @After
    public void after(){
        session.close();
    }
    @Test
    public void selectAllUser(){
//        List<User> users = mapper.selectAllUser();
        for(User user: mapper.selectAllUser()){
            System.out.println(user);
        }
    }
    @Test
    public void selectUser_Role(){
        for (User user : mapper.selectUser_Role()) {
            System.out.println(user);
        }
    }
}
